package com.axend.aerosense.home.adapter;


import android.text.TextUtils;
import android.view.View;

import com.axend.aerosense.common.util.DateUtil;
import com.axend.aerosense.home.entity.WardReportBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.axend.aerosense.home.R;
import com.axend.aerosense.home.databinding.HomeReportListItemBinding;

import org.jetbrains.annotations.NotNull;


public class WardReportAdapter extends BaseQuickAdapter<WardReportBean, BaseDataBindingHolder<HomeReportListItemBinding>> {

    private IReportsClick<WardReportBean> iReportsClick;

    public WardReportAdapter() {
        super(R.layout.home_report_list_item);
    }


    @Override
    protected void convert(@NotNull BaseDataBindingHolder<HomeReportListItemBinding> holder, WardReportBean bean) {

        HomeReportListItemBinding binding = holder.getDataBinding();
        if (null == bean || null == binding) {
            return;
        }

        binding.homeWardName.setText(bean.getReportName());
        String tmp = DateUtil.getStringDateMMddyyyyHHmm(bean.getReportTime());
        binding.homeLogTime.setText(tmp);

        if(!TextUtils.isEmpty(bean.getAdlurl())){
            binding.homeAdlReports.setVisibility(View.VISIBLE);
            binding.homeAdlReports.setOnClickListener(v -> {
                if (null != iReportsClick){
                    iReportsClick.onAdlReportClick(bean);
                }
            });
        }else {
            binding.homeAdlReports.setVisibility(View.GONE);
        }

        if(!TextUtils.isEmpty(bean.getSleepUrl())){
            binding.homeSleepReports.setVisibility(View.VISIBLE);
            binding.homeSleepReports.setOnClickListener(v -> {
                if (null != iReportsClick){
                    iReportsClick.onSleepReportClick(bean);
                }
            });
        }else {
            binding.homeSleepReports.setVisibility(View.GONE);
        }
    }


    public void setiReportsClick(IReportsClick<WardReportBean> iReportsClick) {
        this.iReportsClick = iReportsClick;
    }
}
